package com.dayuanit.dy8.atm.springbootatm.service;

import com.dayuanit.dy8.atm.springbootatm.dto.FlowDTO;
import com.dayuanit.dy8.atm.springbootatm.entity.Flow;
import com.dayuanit.dy8.atm.springbootatm.mapper.FlowMapper;
import com.dayuanit.dy8.atm.springbootatm.util.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class FlowService {

    @Autowired
    private FlowMapper flowMapper;

    public List<FlowDTO> listTop10(int userId) {
        final List<Flow> flows = flowMapper.listTop10(userId);
        final List<FlowDTO> dtoList = new ArrayList<>(flows.size());//3

        for (Flow flow : flows) {
            FlowDTO flowDTO = new FlowDTO();
            dtoList.add(flowDTO);

            flowDTO.setDesc(flow.getFlowDesc());
            flowDTO.setAmount(flow.getAmount());
            flowDTO.setCardNum(flow.getCardNum());
            flowDTO.setCreateTime(DateUtils.dateToString(flow.getCreateTime()));
        }

        return dtoList;
    }
}
